var TankBase = function (x, y, width, height, direction, imageOptions) {
    TankBase.base.call(this, x, y, width, height, imageOptions);
    this.speed = 250;
    this.direction = direction;
    this.render = function (drawEngine) {
        drawEngine.render(this.image, 0, this.direction * this.image.height, this.image.width, this.image.height, this.x, this.y, this.width, this.height);
    };
    this.__weaponTimeout = 0;
    this.weaponTimeout = 0.1;
    this.weaponReload = function (dt) {
        if (this.__weaponTimeout < this.weaponTimeout) {
            this.__weaponTimeout += dt;
        }
    };
    this.createRocket = function (width, height, imageOptions, animationOptions) {
        var tankCenterX = this.x + this.width / 2,
            tankCenterY = this.y + this.height / 2,
            offsetX = 0,
            offsetY = 0,
            _m = this.damage / 30;

        var rocketWidth = Math.round(width * _m),
            rocketHeight = Math.round(height * _m);

        if (this.direction == epam.tankBattles.enum.direction.left) {
            offsetX = -rocketWidth - this.width / 2;
            offsetY = -rocketHeight / 2;
        } else if (this.direction == epam.tankBattles.enum.direction.right) {
            offsetX = this.width / 2;
            offsetY = -rocketHeight / 2;
        } else if (this.direction == epam.tankBattles.enum.direction.up) {
            offsetX = - rocketHeight / 2;
            offsetY = -rocketWidth - this.height / 2;
        } else if (this.direction == epam.tankBattles.enum.direction.down) {
            offsetX = -rocketHeight / 2;
            offsetY = this.height / 2;
        }
        return new Rocket(tankCenterX + offsetX, tankCenterY + offsetY, rocketWidth, rocketHeight, this.direction, this.damage, imageOptions, animationOptions);
    };
    this.beforeFireEvent = function () {
        throw 'The beforeFireEvent() method has not been implemented.'
    };
    this.afterFireEvent = function (rocket) {
        throw 'The afterFireEvent() method has not been implemented.'
    };
    this.fire = function (beforeFire, afterFire) {
        if (this.__weaponTimeout >= this.weaponTimeout) {
            this.__weaponTimeout = 0;
            this.beforeFireEvent();
            var rocket = this.createRocket(this.rocketOptions.width, this.rocketOptions.height, this.rocketOptions.imageOptions, this.rocketOptions.animationOptions);
            this.afterFireEvent(rocket);
            return rocket;
        }
        return null;
    };
},
LightTank = function (x, y, width, height, direction, imageOptions) {
    LightTank.base.call(this, x, y, width, height, direction, imageOptions);
    this.speed = 300;
    this.weaponTimeout = 0.5;
    this.damage = 30;
    this.armor = 1;
},
MediumTank = function (x, y, width, height, direction, imageOptions) {
    MediumTank.base.call(this, x, y, width, height, direction, imageOptions);
    this.speed = 200;
    this.weaponTimeout = 1;
    this.damage = 40;
    this.armor = 3;
}
HeavyTank = function (x, y, width, height, direction, imageOptions) {
    HeavyTank.base.call(this, x, y, width, height, direction, imageOptions);
    this.speed = 100;
    this.weaponTimeout = 2;
    this.damage = 50;
    this.armor = 5;
};

epam.tankBattles.common.extend(TankBase, BaseGameObject);
epam.tankBattles.common.extend(LightTank, TankBase);
epam.tankBattles.common.extend(MediumTank, TankBase);
epam.tankBattles.common.extend(HeavyTank, TankBase);
